<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" href="../ucs.css">
		<link rel="stylesheet" href="../demo.css">
	</head>
	<body>
	<div id="main" ></div>
	<script type="text/javascript" src="../../dist/libs/u-eventhub.js"></script>
	<script type="text/javascript" src="../../dist/libs/engine.js" ></script>
	<script type="text/javascript" src="../../dist/ucsmy-ui.js"></script>
	<script>
		var phoneDM = new UDM({//手机号
			id:'',
			name:'',
			label:"手机号：",
			placeholder:'请输入手机号码',
			validator:[
				{type:"require",msg:"请输入手机号码"},
				{type:"mobile",msg:"手机号码格式错误，请重新输入"}
			]
		});
		var imgInputDM = new UDM({//图像验证码输入框
			id:"imgcode",
			name:"",
			label:"图形验证码：",
			validator:[
				{type:"require",msg:"请输入右侧图形验证码"},
				{
					type:"fn",
					fn:function(v){
						if(v == "tbsf"){
							return true;
						}else{
							return false;
						}
					},
					msg:"验证码错误，请重新输入"
				}
			]
		});
		var imgCode = new UDM({//图像验证码切换
			id:"aaa",
			value:"../images/code.jpg",
			onClick:function(){
				imgCode.setValue("../images/logoe.jpg");
			}
		});

		var getBtnCode = new UDM({//获取短信验证码按钮
			id:"msgbtn",
			count:5,
			onClick:function(){
				var phoneMsg = phoneDM.validate(),
					imgMsg = imgInputDM.validate();
				if(!phoneMsg && !imgMsg){
					phoneDM.setError("手机号已注册");
				}else{
					UEventHub.emit('getcode',true);
				}
			}
		});
		var msgDM = new UDM({//短信验证码input
			id:"msg",
			name:"",
			label:"短信验证码：",
			validator:[
				{type:"require",msg:"请输入短信验证码"},
				{
					type:"fn",
					fn:function(v){
						if(v == 123){
							return true;
						}else{
							return false;
						}
					},
					msg:"短信验证码错误，请重新输入"
				},
				{
					type:"fn",
					fn:function(v){
						if(v == 456){
							return true;
						}else{
							return false;
						}
					},
					msg:"验证码已过期，请重新获取"
				}
			]
		});
		var pswDM = new UDM({//密码
			id:'pwd',
			name:'pwd',
			label:"登录密码：",
			validator:[
				{type:"require",msg:"请输入登录密码"},
				{
					type:"fn",
					fn:function(v){
						if(v == 123){
							return true;
						}else{
							return false;
						}
					},
					msg:"密码必须为 6-16 位字母、数字的组合"
				}
			]
		});
		var pswDM2 = new UDM({//确认密码
			id:'pwd',
			name:'pwd',
			label:"确认登录密码：",
			validator:[
				{type:"require",msg:"请再次输入登录密码"},
				{
					type:"fn",
					fn:function(v){
//						console.log(pswDM.getValue());
						if(v == pswDM.getValue()){
							return true;
						}else{
							return false;
						}
					},
					msg:"两次输入的密码不一致"
				}
			]
		});
		var tjDM = new UDM({//推荐码
			id:'pwd',
			name:'pwd',
			label:"推荐码：",
			autoValidate:false,
			validator:[
				{
					type:"fn",
					fn:function(v){
//						console.log(v)
						if(v && v == 123){
							return true;
						}else{
							return false;
						}
					},
					msg:"推荐码不存在，请重新输入"
				}
			]
		});

		var checkVal = true;
		var checkboxDM = new UDM({
			id:"",
			setChecked:checkVal,
			onClick:function(v){
				console.log(v);	//是否勾选
				checkVal = v;
			}
		});

		var btnRegisterDM = new UDM({
			id:'btn-register',
			name:"",
			onClick:function(){
//				console.log(tjDM.getValue());
				/*推荐码校验*/
				if(tjDM.getValue()){
					var tjMsg = tjDM.validate();
					if(!tjMsg){//校验通过
						console.log(111)
					}else{
						console.log(222)
						return;
					}
				}

				if(!checkVal){//是否勾选协议
					alert("尊敬的用户！您需要勾选“我已阅读并同意《绵阳市商业银行平台服务协议（个人版）》才能注册");
					return;
				}else if(!phoneDM.validate() || !imgInputDM.validate() || !msgDM.validate() || !pswDM.validate() || !pswDM2.validate()){ //校验各数据模型
					console.log('校验没通过！')
					return;
				}else{
					console.log('所有校验通过！');
				}
			}
		});
		//链接
		var URLDM = new UDM({
			agreement:"协议链接",    //协议链接
			login:"../demoLogin/index.html"	//直接登录
		});
		var PageDM = {
			URL:URLDM,
			input1:phoneDM,
			input2:imgInputDM,
			getBtnCode:getBtnCode,
			imgCode:imgCode,
			msgDM:msgDM,
			pswDM:pswDM,
			pswDM2:pswDM2,
			tjDM:tjDM,
			checkboxDM:checkboxDM,
			btn1:btnRegisterDM
		}
	</script>
    </body>
</html>
